#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    int numberOfPairs(vector<vector<int>>& points) {
        int n = points.size();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int flag = 0;
                if (points[i][0] <= points[j][0] &&
                    points[i][1] >= points[j][1]) {
                    for (int t = 0; t < n; t++) {
                        if (t != i && t != j && points[i][1] >= points[t][1] &&
                            points[i][0] <= points[t][0] &&
                            points[j][0] >= points[t][0] &&
                            points[j][1] <= points[t][1]) {
                            flag = 1;
                            break;
                        }
                    }
                    if (!flag) ans++;
                }
                else if (points[i][0] >= points[j][0] &&
                    points[i][1] <= points[j][1]) {
                    for (int t = 0; t < n; t++) {
                        if (t != i && t != j && points[i][1] <= points[t][1] &&
                            points[i][0] >= points[t][0] &&
                            points[j][0] <= points[t][0] &&
                            points[j][1] >= points[t][1]) {
                            flag = 1;
                            break;
                        }
                    }
                    if (!flag) ans++;
                }
            }
        }
        return ans;
    }
};